import axios from 'axios'

const server = axios.create({
    baseURL: 'https://api.it120.cc',
    timeout: 10000
})

// 请求拦截

server.interceptors.request.use(config => {
    // console.log(config)
    if(localStorage.getItem('token')) {
        config.headers.token = localStorage.getItem('token')
    }
    return config
}, err => {
    Promise.reject(err)
})

// 响应拦截
server.interceptors.response.use(res => {
    return res.data
}, err => {
    switch(err.status) {
        case 404:
            console.log('页面找不到了')
        break;
        case 500:
            console.log('服务器错误')
        break;
        default: 
            Promise.reject(err)
        break
    }
})

export default server
